package com.yuan.model_payment.rest;


import com.yuan.model_common.dto.CommonQueryCriteria;
import com.yuan.model_payment.domain.PaymentBill;
import com.yuan.model_payment.service.PaymentBillService;
import com.yuan.model_payment.service.dto.PaymentBillDto;
import com.yuan.model_payment.service.dto.PaymentBillQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Api(tags = "物业便民: 小区缴费管理")
@RestController
@RequestMapping("/api/PaymentBill")
@RequiredArgsConstructor
public class PaymentBillController {

    private final PaymentBillService paymentBillService;

    @ApiOperation("导出/payment/bill")
    @GetMapping(value = "/download")
    public void exportPayBill(HttpServletResponse response, CommonQueryCriteria criteria) throws IOException {
        paymentBillService.download(paymentBillService.queryAll(criteria), response);
    }

    @GetMapping("/findList")
    @Log("查询/api/payment/bill")
    @ApiOperation("查询/payment/bill")
    public ResponseEntity<PageResult<PaymentBillDto>> queryPayBillList(PaymentBillQueryCriteria criteria, Pageable pageable) {
        PageResult<PaymentBillDto> paymentBillPageResult = paymentBillService.queryAll(criteria, pageable);
        return new ResponseEntity<>(paymentBillPageResult, HttpStatus.OK);
    }


    @GetMapping("/findListByType")
    @Log("查询/api/payment/bill")
    @ApiOperation("查询/payment/bill")
    public ResponseEntity<PageResult<PaymentBillDto>> queryPayBillListByType(PaymentBillQueryCriteria criteria, Pageable pageable) {
        PageResult<PaymentBillDto> paymentBillPageResult = paymentBillService.queryAll(criteria, pageable);
        return new ResponseEntity<>(paymentBillPageResult, HttpStatus.OK);
    }

    @Log("新增/api/payment/bill")
    @ApiOperation("新增/payment/bill")
    @PostMapping("/create")
    public ResponseEntity<Object> createPayBill(@Validated @RequestBody PaymentBill resources) {
        paymentBillService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("修改/api/payment/bill/jiaofei")
    @ApiOperation("修改/api/payment/bill/业主缴费")
    @PostMapping("/update/pay1")
    public ResponseEntity<Object> updatePayBillJiaoFei(@Validated(PaymentBill.Update.class) @RequestBody PaymentBill resources) throws Exception {
        paymentBillService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("修改/api/payment/bill")
    @ApiOperation("修改/api/payment/bill")
    @PostMapping("/update")
    public ResponseEntity<Object> updatePayBill(@Validated(PaymentBill.Update.class) @RequestBody PaymentBill resources) throws Exception {
        paymentBillService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除/api/payment/bill")
    @ApiOperation("删除/api/payment/bill")
    @PostMapping("/delete")
    public ResponseEntity<Object> deletePayBill(@RequestParam Integer ids) {
        paymentBillService.delete(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }






}
